{% extends "base.html" %}
{% load url from future %}

{% block content %}

<script>
function mudarPessoa() {
    pessoa = document.getElementById('pessoa')
    nome = document.getElementById('label_nome')
    cpf_cnpj = document.getElementById('label_cpf_cnpj')
    rg_ie = document.getElementById('label_rg_ie')
    if (pessoa.value == 'f') {
        nome.innerHTML = 'Nome:'
        cpf_cnpj.innerHTML = 'Cpf:'
        rg_ie.innerHTML = 'Rg:'
    } else {
        nome.innerHTML = 'Raz&atilde;o Social:'
        cpf_cnpj.innerHTML = 'Cnpj:'
        rg_ie.innerHTML = 'Insc. Est.:'
    }
    return
}

function mudarRevenda() {
    revenda = document.getElementById('revenda')
    fantasia = document.getElementById('fantasia')
    logo = document.getElementById('logo')
    contatos = document.getElementById('contatos')
    if (revenda.value == 'n') {
        fantasia.disabled=true
        logo.disabled=true
        contatos.disabled=true
    } else {
        fantasia.disabled=false
        logo.disabled=false
        contatos.disabled=false
    }
    return   
}
</script>


{% ifequal id "" %}
    <h3>Adicionando Novo Usu&aacute;rio</h3>
{% else %}
    <h3>Alterando Usu&aacute;rio</h3>
{% endifequal %}

<br />

<a class="btn btn-success" href="/usuarios"><i class="icon-list-alt icon-white"></i>  Lista de Usu&aacute;rios</a>

<br /><br />

<form enctype="multipart/form-data" method='post' class="form-horizontal">
  {% csrf_token %}
  <input type='hidden' id='id' name='id' value={{ id }} />
  <fieldset>

    <div class="control-group"><label class="control-label" for="usuario">Usu&aacute;rio:</label>
    <div class="controls"><input value='{{ usuario }}' type="text" class="input-xlarge" id="usuario" name='usuario'> Administrador? <select name='admin' class='input-mini'><option {% ifequal admin "n" %}selected='selected'{% endifequal %} value='n'> N&atilde;o </option><option {% ifequal admin "s" %}selected='selected'{% endifequal %} value='s'> Sim </option></select></div></div>

    <div class="control-group"><label class="control-label" for="senha">Senha:</label>
    <div class="controls"><input value='{{ senha }}' type="password" class="input-xlarge" id="senha" name='senha'> Re-digite a Senha: <input value='{{ resenha }}' type="password" class="input-xlarge" id="re-senha" name='re-senha'></div></div>

    <div class="control-group"><label class="control-label" for="pessoa">Pessoa:</label>
    <div class="controls"><select onchange='mudarPessoa()' id='pessoa' name='pessoa' class='input-small'><option {% ifequal pessoa "f" %}selected='selected'{% endifequal %} value='f'> F&iacute;sica </option><option {% ifequal pessoa "j" %}selected='selected'{% endifequal %}value='j'> Jur&iacute;dica </option></select></div></div>

    <div class="control-group"><label class="control-label" for="nome"><span id='label_nome'>Nome:</span></label>
    <div class="controls"><input value='{{ nome }}' type="text" class="input-xxlarge" id="nome" name='nome'></div></div>

    <div class="control-group"><label class="control-label" for="cpf_cnpj"><span id='label_cpf_cnpj'>Cpf:</span></label>
    <div class="controls"><input value='{{ cpf_cnpj }}' type="text" class="input-large" id="cpf_cnpj" name='cpf_cnpj'> <span id='label_rg_ie'>Rg:</span> <input value='{{ rg_ie }}' type="text" class="input-large" id="rg_ie" name='rg_ie'></div></div>


    <div class="control-group"><label class="control-label" for="endereco">Endere&ccedil;o:</label>
    <div class="controls"><input value='{{ endereco }}' type="text" class="input-xxlarge" id="endereco" name='endereco'></div></div>

    <div class="control-group"><label class="control-label" for="bairro">Bairro:</label>
    <div class="controls"><input value='{{ bairro }}' type="text" class="input-xlarge" id="bairro" name='bairro'></div></div>

    <div class="control-group"><label class="control-label" for="cidade">Cidade:</label>
    <div class="controls"><input value='{{ cidade }}' type="text" class="input-xlarge" id="cidade" name='cidade'> Estado: <input value='{{ estado }}' type="text" class="input-mini" id="estado" name='estado'> Cep: <input value='{{ cep }}' type="text" class="input-xlarge" id="cep" name='cep'></div></div>

    <div class="control-group"><label class="control-label" for="telefone">Telefone:</label>
    <div class="controls"><input value='{{ telefone }}' type="text" class="input-xlarge" id="telefone" name='telefone'> Celular: <input value='{{ celular }}' type="text" class="input-xlarge" id="celular" name='celular'></div></div>

    <div class="control-group"><label class="control-label" for="email">E-mail:</label>
    <div class="controls"><input value='{{ email }}' type="text" class="input-xlarge" id="email" name='email'></div></div>

    <div class="control-group"><label class="control-label" for="grupo">Grupo:</label>
        <div class="controls">
            {{ form.grupo }}
        </div>
    </div>
    
    <div class="control-group"><label class="control-label" for="email">Revenda?</label>
    <div class="controls"><select onchange='mudarRevenda()' name='revenda' id='revenda' class='input-mini'><option {% ifequal revenda "n" %}selected='selected'{% endifequal %} value='n'> N&atilde;o </option><option {% ifequal revenda "s" %}selected='selected'{% endifequal %} value='s'> Sim </option></select></div></div>

    <div class="control-group"><label class="control-label" for="fantasia">Nome da Revenda:</label>
    <div class="controls"><input value='{{ fantasia }}' disabled='disabled' type="text" class="input-xxlarge" id="fantasia" name='fantasia'></div></div>

    <div class="control-group"><label class="control-label" for="logo">Logotipo:</label>
    <div class="controls">
        <input type="hidden" name="logo_file" id="logo_file" value="{{ logo }}" />
        {% ifnotequal logo "" %}
            <div style='width:100px;float:left;margin-right:20px;'>
                <img width="100" src="/{{ logo }}" />
            </div>{% endifnotequal %}
            <input value='{{ logo }}' disabled='disabled' type='file' id='logo' name='logo' type='logo' />

    {% ifnotequal logo "" %}
    <br />
    ou<br />
    <input type="checkbox" id="remover_logo" name="remover_logo" value="sim" />Remover o logotipo.
    {% endifnotequal %}

    </div></div>

    <div class="control-group"><label class="control-label" for="contatos">Contatos da Revenda:</label>
    <div class="controls"><input value='{{ contatos }}' disabled='disabled' type="text" class="input-xxlarge" id="contatos" name='contatos'></div></div>

    <div class="form-actions">
      {% ifequal id "" %}
          <button type="submit" id='acao' name='acao' value='cadastrar_usuario' class="btn btn-primary"> Cadastrar Usu&aacute;rio </button>
      {% else %}
          <button type="submit" id='acao' name='acao' value='editar_usuario' class="btn btn-primary"> Salvar Altera&ccedil;&otilde;es </button>
      {% endifequal %}
    </div>
  </fieldset>
</form>

<script>
mudarPessoa()
mudarRevenda()
</script>

{% endblock %}
